<template>
	<view>
		<view class="inputAccount">
			<text class="account">账号</text>
			<input class="inputA" v-model="form.account" placeholder="请输入您的账号" />
		</view>
		<view class=" inputAccount">
			<text class="account">密码</text>
			<input class="inputA" v-model="form.password" password type="password" placeholder="请输入您的密码" />
		</view>
		<view class=" loginView">
			<button class="loginButton" @click="goLogin">
				<text class="loginText">登录</text>
			</button>
		</view>
		<text class="notLoginText" @click="toBack">暂不登录</text>
	</view>
</template>

<script>
	export default {
		onLoad() {
			// #ifdef MP-WEIXIN || APP-PLUS
			// this.isThreeLogin = true;
			// #endif

			// #ifdef H5
			// if (this.$util.isWeiXinBrowser()) {
			// 	this.isThreeLogin = true;
			// }
			// #endif
		},
		data() {
			return {
				form: {
					account: '',
					password: ''
				},
				isThreeLogin: false
			}
		},
		methods: {
			toBack(e) {
				uni.navigateBack();
			},
			goThreeLogin: async function() {
				// #ifdef MP-WEIXIN
				// this.$Router.push('/pages/login/wxlogin');
				uni.navigateTo({
					url: '/pages/login/wxlogin'
				})
				// #endif

				// // #ifdef H5

				// if (this.$util.isWeiXinBrowser()) {
				// 	let res = await this.$api.getAuthUrl({
				// 		platform: 'wechat',
				// 		url: window.location.origin + '/pages/login/auth'
				// 	});
				// 	if (!res.code) {
				// 		this.$u.toast(res.msg);
				// 		return;
				// 	}
				// 	window.location.href = res.data;
				// }
				// // #endif

				// // #ifdef APP-PLUS
				// let that = this;
				// var all, Service;
				// // 1.发送请求获取code
				// plus.oauth.getServices(
				// 	function(Services) {
				// 		all = Services;
				// 		Object.keys(all).some(key => {
				// 			if (all[key].id == 'weixin') {
				// 				Service = all[key];
				// 			}
				// 		});
				// 		Service.authorize(
				// 			async function(e) {
				// 				console.log(e);
				// 				let res = await that.$api.goAppLogin({ code: e.code, scope: e.scope });
				// 				if (!res.code) {
				// 					that.$u.toast(res.msg);
				// 					return;
				// 				}
				// 				if (res.data.user) {
				// 					that.$u.vuex('vuex_token', res.data.user.token);
				// 					that.success(2);
				// 					return;
				// 				}
				// 				that.$u.vuex('vuex_third', res.data.third);
				// 				that.$Router.push({path:'/pages/login/register',query:{bind:'bind'}});
				// 			},
				// 			function(e) {
				// 				that.$u.toast('授权失败！');
				// 			}
				// 		);
				// 	},
				// 	function(err) {
				// 		console.log(err);
				// 		that.$u.toast('授权失败！');
				// 	}
			);
			// #endif
		},
		goLogin: async function() {
			if (this.form.account == "" || this.form.password == "") {
				uni.showToast({
					title: "请完善信息！",
					icon: "error"
				});
				return;
			}
			if (this.vuex_wx_uid) {
				this.form.wx_user_id = this.vuex_wx_uid;
			}
			let res = await this.$api.goLogin(this.form);
			if (!res.code) {
				uni.showToast({
					icon: 'none',
					title: res.msg
				})
				return;
			}
			this.$u.vuex('vuex_token', res.data.token);
			uni.redirectTo({
				url: '/pages/write/write',
				complete() {
					uni.showToast({
						title:"RD登录成功！"
					})
				}
			})
			// uni.navigateBack({success:()=> {
			// 	uni.showToast({
			// 	title: "RD登录成功！"
			// });
			// }});
			 // uni.showToast({
			 //     title: 'RD登录成功！',
			 //     duration: 2000,
			 //     complete: function () {
			 //       // 2000毫秒后自动关闭Toast
			 //       setTimeout(function () {
			 //         uni.navigateBack(); // 返回上一页
			 //       }, 1000);
			 //     }
			 //   });
			// this.success(2);
		},
	}
	}
</script>

<style scoped>
	.notLoginText {
		display: block;
		text-align: center;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #020202;
		margin-top: 64rpx;
	}

	.loginText {
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 28rpx;
		color: #020202;
	}

	.loginView {
		width: 100%;
		height: 100rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin-top: 48rpx;
	}

	.loginButton {
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 10rpx 32rpx 10rpx 32rpx;
		height: 80rpx;
		background: #FBCB11;
		border-radius: 40rpx 40rpx 40rpx 40rpx
	}

	.inputA {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #646566;
		line-height: 40rpx;
		padding-left: 44rpx
	}

	.account {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #000000;
		line-height: 40rpx;
		margin-left: 32rpx;
	}

	.inputAccount {
		background: #FFFFFF;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		width: 100%;
		height: 88rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
	}
</style>